import axios from "axios";
import {getCookie} from "@/utils/Cookie";
import baseInfo from '@/default/index'
const token = getCookie('like-admin')

const api = axios.create({
    baseURL:'',
    withCredentials:false,
    maxRedirects:5,
    timeout:8000,
    headers: {
        "Content-Type": "application/json",
        "Accept":"*/*",
    }
})

// 请求拦截器

api.interceptors.request.use(
    config=>{
        if (token){
            config.headers['like-admin'] = token
        }
        config.headers['like-lang'] = baseInfo.lang

        return config
    },
    error => {
        return Promise.reject(error)
    }
)

api.interceptors.response.use(
    response =>{
        let code = response.data.code
        switch (code){
            case 200:{
                return response.data
            }
            default:{
                return Promise.reject(response.data)
            }
        }
    },
    error => {
        return Promise.reject(error)
    }
)

export default api